﻿using Daq.Utils;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Telerik.Windows.Controls;

namespace Daq.Views
{
    /// <summary>
    /// LicenseWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LicenseWindow : RadWindow
    {
        public LicenseWindow(string id)
        {
            InitializeComponent();
            txtId.Text = id;
        }

        private void RadWindow_PreviewClosed(object sender, WindowPreviewClosedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Clipboard.SetDataObject(txtId.Text);
            Alert(new DialogParameters
            {
                Content = "复制成功",
                Header = "提示"
            });
        }

        private async void btnImportLicense_Click(object sender, RoutedEventArgs e)
        {
            RadOpenFileDialog openFileDialog = new RadOpenFileDialog()
            {
                Header = "打开文件",
            };
            openFileDialog.Owner = this;
            openFileDialog.ShowDialog();
            if (openFileDialog.DialogResult == true)
            {
                string selectedFileName = openFileDialog.FileName;
                await Task.Run(() =>
                {
                    File.Copy(selectedFileName, "./.license");
                });

                await LicenseHelper.RestartApplication();
            }
        }

    }
}
